package ch3;

import java.util.concurrent.atomic.AtomicInteger;

/**
 *类说明：演示基本类型的原子操作类
 */
public class UseAtomicInt {
    private static AtomicInteger ai = new AtomicInteger(10);

    public static void main(String[] args) {
        int getAndIncrement = ai.getAndIncrement();
        System.out.println(getAndIncrement);  //10

        int incrementAndGet = ai.incrementAndGet();
        System.out.println(incrementAndGet);  //12
//        new Thread(new TestThead1()).run();
//        new Thread(new TestThead1()).run();
//        new Thread(new TestThead2()).run();
//        new Thread(new TestThead2()).run();

    }


//    static class TestThead1 implements Runnable{
//        @Override
//        public void run() {
//            int getAndIncrement = ai.getAndIncrement();
//            System.out.println("线程1：" +getAndIncrement);  //10
//        }
//    }
//
//    static class TestThead2 implements Runnable{
//        @Override
//        public void run() {
//            int incrementAndGet = ai.incrementAndGet();
//            System.out.println("线程2：" +incrementAndGet);  //12
//        }
//    }
}
